package com.storm.formatter
{
	public class StringFormatter {
		public function StringFormatter() {
		}
		
		public static function format(pattern:String, params:Array):String {
			var reg:RegExp = /%(s|d)/;
			var splitArray:Array = pattern.split(reg);
			for (var i:int = 0; i < splitArray.length / 2; i++) {
				var p:int = i * 2 + 1;
				var param:Object = params[i];
				switch (splitArray[p]) {
					case "s":
						if (param is String) {
							splitArray[p] = param;
						} else {
							return "";
						}
						break;
					case "d":
						if (param is Number) {
							splitArray[p] = String(param);
						} else {
							return "";
						}
						break;
				}
			}
			return splitArray.join("");
		}
	}
}